package com.bjsxt.reflex;

import java.lang.reflect.Method;

public class GetMethod2 {
    public static void main(String[] args) throws Exception {
        Class clazz = Users.class;
        Method m = clazz.getMethod("setUsername", String.class);
        //实例化对象
        Object obj = clazz.newInstance();
        //通过setUserName()赋值
        m.invoke(obj,"oldlu"); //obj相当于this的隐式参数
        //通过getUserName()获取值
        Method m1 = clazz.getMethod("getUsername");
        Object value = m1.invoke(obj);
        System.out.println(value);

    }
}
